package com.datam.filter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import com.datam.dao.CompanyInfoDAO;
import com.datam.dao.CompanyPkInfoDAO;
import com.datam.dao.SysUserDAO;
import com.datam.dao.YJDAO;
import com.datam.domain.CompanyInfoDO;
import com.datam.domain.CompanyPkInfoDO;
import com.datam.domain.SysUserDO;
import com.datam.query.QueryCompanyInfo;
import com.datam.query.QueryCompanyPkInfo;
import com.datam.query.QuerySysUser;
import com.datam.utils.YjInfoUtils;



@Component
public class LoadInfo  implements CommandLineRunner {
	
	@Autowired
	YJDAO yJDAO ; 
	
	@Autowired
	CompanyPkInfoDAO companyPkInfoDAO;
	
	@Autowired
	CompanyInfoDAO companyInfoDAO;
	
	@Autowired
	SysUserDAO sysUserDAO ;
	
	
	
    @Override
    public void run(String... args) throws Exception {
    	YjInfoUtils.yj.clear();
    	YjInfoUtils.pfl.clear();
    	YjInfoUtils.pk.clear();
    	YjInfoUtils.gs.clear();
    	YjInfoUtils.pkyj.clear();
    	YjInfoUtils.zyj.clear();
    	YjInfoUtils.yh.clear();
    	//加载预警
    	List<Map> yj = yJDAO.selectPkyjByStatus();
    	for(Map m : yj){
    		try {
        		YjInfoUtils.yj.put(m.get("ITEMCODE")+"_"+m.get("code"), Float.valueOf(m.get("OUTPUTSTANDARD")+""));
        		if("1".equals(m.get("STATE"))){
        			YjInfoUtils.pkyj.put(m.get("ITEMCODE")+"_"+m.get("code"),m);
        		}
    		} catch (Exception e) {
    			e.printStackTrace();
				System.out.println(m.get("ITEMCODE")+"_"+m.get("code")+"异常");
			}
    	}
    	//加载初始化排放量
    	List<Map> pfl = yJDAO.selectPfl();
    	for(Map m : pfl){
    		YjInfoUtils.pfl.put(m.get("code")+"_"+m.get("nm_id"), Float.valueOf(m.get("value")+""));
    	}
    	//查询排口信息
    	List< CompanyPkInfoDO > pkdata= companyPkInfoDAO.selectCompanyPkInfoList(new QueryCompanyPkInfo());
    	for(CompanyPkInfoDO d : pkdata){
    		YjInfoUtils.pk.put(d.getCODE(), d);
    	}
    	//公司信息
    	List< CompanyInfoDO > gsdata= companyInfoDAO.selectCompanyInfoList(new QueryCompanyInfo());
    	for(CompanyInfoDO c : gsdata){
    		YjInfoUtils.gs.put(c.getID()+"", c);
    	}
    	//查询总预警
    	List<Map> zyj =  yJDAO.selectZyj();
    	for(Map m : zyj){
    		YjInfoUtils.zyj.put(m.get("COMPANYID")+"", m.get("STATE")+"");
    	}
    	//查询用户
    	List< SysUserDO >  users = sysUserDAO.selectSysUserList(new QuerySysUser());
    	for(SysUserDO user : users){
    		YjInfoUtils.yh.put(user.getCompanyInfo(),user);
    	}
    	
    }
}
